<?php

namespace app\api\model;

use think\Model;

class SeeMe extends Model
{
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    /**
     * 看过我
     * @param $user_id
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    public function seeMe($user_id)
    {
        $data = $this->alias('a')
            ->join('user_info b', 'a.user_id = b.user_id')
            ->where('see_id', $user_id)
            ->order('a.updatetime desc')
            ->field("b.user_id,b.avatar,b.gender,b.username,b.status as auth_status,a.num,b.birthday,FROM_UNIXTIME(a.updatetime,'%Y-%m-%d %H:%i:%s') as createtime")
            ->paginate(10);
        foreach ($data as $k => $v) {
            $data[$k]['user_age'] = user_age($v['birthday']);//年龄
            $data[$k]['members'] = model('members')->where('user_id', $v['user_id'])->value('status') ?? 0;//会员等级
        }
        return $data;
    }
}